package com.steven.im.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.steven.im.R;
import com.steven.im.base.BaseActivity;
import com.steven.im.utils.ScreenUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class IMSearchActivity extends BaseActivity {
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.tv_searchContent)
    TextView searchContent;
    @BindView(R.id.ll_search)
    LinearLayout ll_search;
    @BindView(R.id.tv_noThisFriend)
    TextView tv_noThisFriend;

    @Override
    public void setListen() {
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String content = etSearch.getText().toString();
                if (content.length() > 0) {
                    ll_search.setVisibility(View.VISIBLE);
                    searchContent.setText(content);
                } else {
                    ll_search.setVisibility(View.GONE);
                }
            }
        });
    }

    @Override
    public void setTitleBarColor() {

    }

    @Override
    public int intiLayout() {
        return R.layout.activity_im_search;
    }

    @Override
    public void initView() {
        showSoftInputFromWindow(etSearch);
    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.tv_cancel, R.id.ll_search})
    public void onViewClicked(View view) {
        if (ScreenUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.tv_cancel://关闭本页面
                finish();
                break;
            case R.id.ll_search://点击进行搜索
                //网络搜索用户
                startActivity(new Intent(IMSearchActivity.this, IMAddFriendActivity.class));
                break;
        }
    }

    /**
     * EditText获取焦点并显示软键盘
     */
    public void showSoftInputFromWindow(EditText editText) {
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
        IMSearchActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }

}
